<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增员工')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="submitHandler()">
                    <i class="fa fa-plus"></i> 添加员工
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<th:block th:include="include :: datetimepicker-js"/>


<script th:inline="javascript">
    var prefix = ctx + "contractManage";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        getData();
    });

    function getData() {
        var columns = [];
        var check = {checkbox: true};
        var cType = {field: 'cType', title: '合同办理建议'};
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var compName = {field: 'compName', title: '公司名称'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '岗位名称'};
        var JoinDate = {field: 'JoinDate', title: '入职日期'};
        var ConCount = {field: 'ConCount', title: '合同次数'};
        var ContractTitle = {field: 'ContractTitle', title: '合同签约单位'};
        var ConTypeTitle = {field: 'ConTypeTitle', title: '合同类型'};
        var ConPropertyTitle = {field: 'ConPropertyTitle', title: '合同属性'};
        var conno = {field: 'conno', title: '合同编号'};
        var ConBeginDate = {field: 'ConBeginDate', title: '合同开始日期'};
        var conterm = {field: 'conterm', title: '合同期'};
        var ConEndDate = {field: 'ConEndDate', title: '合同结束日期'};

        columns.push(check,cType,badge,name,compName,depName,jobName,JoinDate,ConCount,ContractTitle,ConTypeTitle);
        columns.push(ConPropertyTitle,conno,ConBeginDate,conterm,ConEndDate);

        var options = {
            code: "eid",
            uniqueId: "eid",
            url: prefix + "/findManageEmp",
            height: $(window).height() - 120,
            modalName: "新增员工",
            columns: columns
        };
        $.table.init(options);
    }

    function submitHandler() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        var allEid = "";
        if (row.length == 0) {
            $.modal.alertWarning("请选择人员");
            return;
        }

        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allEid += row[i].eid
            } else {
                allEid += row[i].eid + ","
            }
        }
        $.ajax({
            async: false,
            url: prefix + "/addManageEmp",
            data: {
                "allEid": allEid,
                "type" : '4'
            },
            type: "post",
            dataType: "json",
            success: function (data) {

                //todo 这里需要判断data返回值
                if (data.code == 0) {
                    $.modal.alertWarning("添加成功！");
                    $.modal.close();
                    $.modal.reload();
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务繁忙");
                } else {
                    $.modal.alertWarning(data.message);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>


</body>
</html>